<template>
  <div>
    <AdminNavi/>
    <!--    主题-->
    <el-tabs v-model="activeName" tab-position="left" style="width: 80%;margin: 0 auto">
      <el-tab-pane label="用户管理" name="second"><UserAdmin></UserAdmin></el-tab-pane>
     <el-tab-pane label="商品管理" name="third"><ProductAdmin></ProductAdmin></el-tab-pane>
    </el-tabs>
  </div>

</template>

<script>
import axios from "axios";
import {baseURL} from "../../public/urlConfig";
import AdminNavi from "@/components/AdminNavi";
import UserAdmin from "@/components/UserAdmin";
import ProductAdmin from "@/components/ProductAdmin";
export default {
  name: "Admin",
  components: {AdminNavi,UserAdmin,ProductAdmin},
  data() {
    return {
      baseURL: baseURL,
      msg:"",
      form:{},
      username: localStorage.getItem("username"),
      activeName: 'second',
      userAddr:[],
      userId:localStorage.getItem("userId"),
    }
  },
  created() {
    this.load()
    if(localStorage.getItem("adminId")===null){
      this.$message.error("请登录")
      this.$router.push('/adminlogin')
    }
  },
  methods: {
    load() {
      axios.get(baseURL+"/user/one/"+localStorage.getItem("username")
      ).then(res => {
        this.form=res.data
      })
      axios.get(baseURL+"/user-addr/addr/"+this.userId).then(
          res=>{this.userAddr=res.data})
    },
    childclick(item){
      this.userAddr=item
      this.load()
    },
    save() {
      axios.post(baseURL+"/user", this.form).then(res => {
        if (res.data) {
          this.$message.success("保存成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("保存失败")
        }
      })
    },
    deleteOne(id){
      axios.delete(baseURL+"/user-addr/deleteOne",{
        params:{
          id:id
        }
      }).then(
          res=>{
            if(res.data===true)this.$message.success("删除成功")
            else this.$message.error("删除失败")
            this.load()
          }
      )
    },
    update(id){
      axios.get(baseURL+"/user-addr/updateCommonAddr",{
        params:{
          id:id
        }
      }).then(
          res=>{
            if(res.data===true)this.$message.success("修改成功")
            else this.$message.error("修改失败")
            this.load()
          }
      )
    }
  }
}

</script>

<style scoped>
.adminContainer {
  height: 100%;
}

.el-aside {
  background-color: #131212;
}

.el-main {
  background-color: #8c939d;
}

</style>